/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ericsson.nfc.signing.record;

/**
 *
 * @author emarkki
 */
class Arrays {
       
    public static boolean equals(byte[] bytes1, byte[] bytes2) {
        if(bytes1 == null && bytes2 == null) {
            return true;
        } else if(bytes1 == null || bytes2 == null) {
            return false;
        }
        
        if(bytes1.length != bytes2.length) {
            return false;
        }
        
        for(int i = 0; i < bytes1.length; i++) {
            if(bytes1[i] != bytes2[i]) {
                return false;
            }
        }
        
        return true;
    }
    
    public static int hashCode(byte bytes[]) {
        
        if (bytes == null) {
            return 0;
        }
        
        int result = 1;
        
        for(int i = 0; i < bytes.length; i++) {
            result = 31 * result + bytes[i];
        }

        return result;
    }

    public static boolean equals(Object[] o1, Object[] o2) {
        if(o1 == null && o2 == null) {
            return true;
        } else if(o1 == null || o2 == null) {
            return false;
        }
        
        if(o1.length != o2.length) {
            return false;
        }
        
        for(int i = 0; i < o1.length; i++) {
            if(o1[i] != o2[i]) {
                return false;
            }
        }
        
        return true;
    }
    
    public static int hashCode(Object[] bytes) {
        
        if (bytes == null) {
            return 0;
        }
        
        int result = 1;
        
        for(int i = 0; i < bytes.length; i++) {
            result = 31 * result + (bytes[i] == null ? 0 : bytes[i].hashCode());
        }

        return result;
    }
}
